package com.ybwh.springboot2.sharding4.ext.kengen;

import com.ybwh.springboot2.uidgenerator.BaiduUidGenerator;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;

import java.util.Properties;

/**
 * <p>
 *  百度UidGenerator
 * </p>
 *
 * @author fanbeibei
 * @version 1.0.0
 * @date 2023/4/12 14:51
 */
public class UidKeyGenerator implements ShardingKeyGenerator {
    private Properties properties = new Properties();


    @Override
    public Comparable<?> generateKey() {
        // https://github.com/baidu/uid-generator/blob/master/README.zh_cn.md
        return BaiduUidGenerator.getInstance().genUid();
    }

    @Override
    public String getType() {
        //对应 spring.shardingsphere.sharding.tables.TTTTT.key-generator.type  的值
        return "BaiduUid";
    }

    @Override
    public Properties getProperties() {

        return properties;
    }

    @Override
    public void setProperties(Properties properties) {
        // 获取 spring.shardingsphere.sharding.tables.TTTT.key-generator.props.XXX值 ,塞到properties里
        this.properties = properties;
    }
}
